package com.example.onlineeducation.ui.auth

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.view.View
import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import com.example.onlineeducation.BuildConfig
import com.example.onlineeducation.R
import com.example.onlineeducation.base.BaseActivity
import com.example.onlineeducation.databinding.LoginActivityBinding
import com.example.onlineeducation.databinding.RegisterActivityBinding
import com.example.onlineeducation.utils.YcLoopCountDown
import com.example.onlineeducation.viewmodel.LoginVM
import com.example.onlineeducation.widget.YcAlbumOrCameraPopupWindow
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.yc.jetpacklib.extension.showToast
import com.yc.jetpacklib.extension.ycIsEmpty
import com.yc.jetpacklib.extension.ycIsNotEmpty
import com.yc.jetpacklib.manager.YcActivityManager
import com.yc.jetpacklib.net.doSuccess
import com.yc.jetpacklib.utils.YcRegularUtil
import com.yc.jetpacklib.utils.YcRegularUtil.ycRegular

import java.util.*

/**
 *  登录
 */
class RegisterActivity : BaseActivity<RegisterActivityBinding>(RegisterActivityBinding::inflate) {

    companion object {
        fun newInstance(context: Context) {
            context.startActivity(Intent(context, RegisterActivity::class.java).apply {
            })
        }
    }

    private lateinit var mPopup: YcAlbumOrCameraPopupWindow
    private var sexId:String = ""
    private lateinit var mRegisterSecondLauncher: ActivityResultLauncher<Intent>
    override fun initImmersionBar() {
        ImmersionBar.with(this)
            .statusBarColor(R.color.colorPrimary)
            .statusBarDarkFont(false)
            .hideBar(BarHide.FLAG_SHOW_BAR)
            .fitsSystemWindows(true)
            .init()
    }

    override fun RegisterActivityBinding.initView() {
        ivActionbarLeft.setOnClickListener {
            finish()
        }
        mPopup = YcAlbumOrCameraPopupWindow(this@RegisterActivity, object :
            YcAlbumOrCameraPopupWindow.OnCameraOrAlbumSelectListener {
            override fun OnSelectFirst() {
                etSex.setText("男")
                sexId = "1"
            }

            override fun OnSelectSecond() {
                etSex.setText("女")
                sexId = "2"
            }

            override fun OnSelectCancel() {

            }
        })
        mPopup.setBtnFirstText("男")
        mPopup.setBtnSecondText("女")
        etSex.setParentClick { mPopup.showAtLocation(R.layout.register_activity) }
        btnNext.setOnClickListener {
            if(etName.getText().ycIsEmpty()){
                showToast("请输入姓名!")
                return@setOnClickListener
            }
            if(sexId.ycIsEmpty()){
                showToast("请选择性别!")
                return@setOnClickListener
            }
            if(!etIdNum.getText().ycRegular(YcRegularUtil.ID_CARD)){
                showToast("请输入正确的身份证号!")
                return@setOnClickListener
            }
            if(!etPhone.getText().ycRegular(YcRegularUtil.PHONE)) {
                showToast("请输入正确的手机号!")
                return@setOnClickListener
            }

            RegisterSecondActivity.newInstance(this@RegisterActivity,etName.getText()
                ,etPhone.getText(),etIdNum.getText(),sexId,mRegisterSecondLauncher)
        }
        mRegisterSecondLauncher =
            RegisterSecondActivity.getLauncher(this@RegisterActivity) {
                finish()
            }
    }




}